package team.ttorder.ttorder.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import team.ttorder.ttorder.dao.UserMapper;
import team.ttorder.ttorder.model.User;
import team.ttorder.ttorder.utils.MD5Utils;

@Service
public class UserServieImpl implements IUserService {

	@Autowired
	private UserMapper userMapper;

	@Override
	public void registerUser(User user) {
		// 加密
		user.setPassword(MD5Utils.getMD5Code(user.getPassword()));
		user.setRole(1);
		userMapper.insert(user);
	}

	@Override
	public User loginUser(User user) {
		User u = userMapper.getUserByPhone(user.getPhone());
		if (u != null) {
			user.setPassword(MD5Utils.getMD5Code(user.getPassword()));
			if (u.getPassword().equals(user.getPassword())) {
				return u;
			}
		}
		return null;
	}

}
